package com.kizuki.io;

import java.io.*;

public class TestDataStream {

    public static void main(String[] args) {
        write();
        read();
    }

    private static void read() {
        File f = new File("d:/java/learnio/TestBuffered.txt");
        try (DataInputStream dis =new DataInputStream(new FileInputStream(f))){
            boolean b= dis.readBoolean();
            int i = dis.readInt();
            String str = dis.readUTF();

            /**
             * 读取数据顺序要跟write对应
             */
            System.out.println("读取到布尔值:"+b);
            System.out.println("读取到整数:"+i);
            System.out.println("读取到字符串:"+str);

        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("java.io.EOFException");
        }

    }

    private static void write() {
        File f = new File("d:/java/learnio/TestBuffered.txt");
        try (DataOutputStream dos =new DataOutputStream(new FileOutputStream(f))){
            dos.writeBoolean(true);
            dos.writeInt(300);
            dos.writeUTF("123 this is gareen");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
